﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;



// Input Variables : 

// Functions :
// public void print(string strFilePath, int intFontSize, string strFont)

// Return : 

namespace SPA_Prototype
{
    public enum GUEST_BILL
    {
        DATE, NUMBER, STAFF_NUMBER, ROOM, CUSTOMER,
        NO_1, NO_2, NO_3, NO_4, NO_5, NO_6,
        DESC_1, DESC_2, DESC_3, DESC_4, DESC_5, DESC_6,
        CODE_1, CODE_2, CODE_3, CODE_4, CODE_5, CODE_6,
        QTY_1, QTY_2, QTY_3, QTY_4, QTY_5, QTY_6,
        UNIT_PRICE_1, UNIT_PRICE_2, UNIT_PRICE_3, UNIT_PRICE_4, UNIT_PRICE_5, UNIT_PRICE_6,
        USD_1, USD_2, USD_3, USD_4, USD_5, USD_6,
        VND_1, VND_2, VND_3, VND_4, VND_5, VND_6,
        DISCOUNT_1, DISCOUNT_2, DISCOUNT_3, DISCOUNT_4, DISCOUNT_5, DISCOUNT_6,
        NOTE_1, NOTE_2, NOTE_3, NOTE_4, NOTE_5, NOTE_6,
        TOTAL, TOTAL_EX,
        DISCOUNT_TOTAL, DISCOUNT_TOTAL_EX,
        EXCHANGE_RATE, VOUCHER, TIPS,
        TOTAL_FINAL, EQUIVALENT
    }
                            
    public struct InvoiceData
    {
        public int index;
        public GUEST_BILL ID;
        public int X;
        public int Y;
        //public int MaxLength;
        public string Data;
    }

    public class PrintReport
    {
        private List<InvoiceData> _Data;
        // Declare and initialize three instances for printing: 
        private System.Windows.Forms.PrintDialog prnDialog;
        private System.Windows.Forms.PrintPreviewDialog prnPreview;
        private System.Drawing.Printing.PrintDocument prnDocument;

        private int leftMargin = 0;
        private int rightMargin = 0;
        private int topMargin = 0;
        private int bottomMargin = 0;
        private int InvoiceWidth = 0;
        private int InvoiceHeight = 0;

        // constructor
        public PrintReport(List<InvoiceData> data)
        {
            _Data = data;            
            prnDialog = new System.Windows.Forms.PrintDialog();
            prnPreview = new System.Windows.Forms.PrintPreviewDialog();
            prnDocument = new System.Drawing.Printing.PrintDocument();
            prnDocument.DefaultPageSettings.Landscape = false;

            PaperSize paperSize = new PaperSize("Invoice", 830, 600);
           
            prnDocument.DefaultPageSettings.PaperSize = paperSize;

            // the Event of 'PrintPage'
            prnDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(prnDocument_PrintPage);            
        }

        #region Font and Color:------------------
        // Font and Color:------------------
        // Invoice Font
        private Font InvoiceFont = new Font("Arial", 10, FontStyle.Regular);
        // Black Color
        private SolidBrush BlackBrush = new SolidBrush(Color.Black);
        #endregion

        // Draw Data to Invoice

        private void SetInvoiceData(Graphics g)
        {    
            int i;
            long DataCount = _Data.LongCount();            
            for (i = 0; i < DataCount; i++)
            {
                g.DrawString(_Data[i].Data, InvoiceFont, BlackBrush, _Data[i].X, _Data[i].Y);
            }                  
        }
        //Print
        public void PrintInvoice()
        {            
            try
            {
                prnDocument.Print();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        //Print Dialog Show
        public void DisplayDialog()
        {
            try
            {
                prnDialog.Document = this.prnDocument;
                DialogResult ButtonPressed = prnDialog.ShowDialog();
                // If user Click 'OK', Print Invoice
                if (ButtonPressed == DialogResult.OK)
                    prnDocument.Print();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        // Print Preview
        public void DisplayInvoice()
        {
            prnPreview.Document = this.prnDocument;

            try
            {
                prnPreview.ShowDialog();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        } 

        private void prnDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            leftMargin = (int)e.MarginBounds.Left;
            rightMargin = (int)e.MarginBounds.Right;
            topMargin = (int)e.MarginBounds.Top;
            bottomMargin = (int)e.MarginBounds.Bottom;
            InvoiceWidth = (int)e.MarginBounds.Width;
            InvoiceHeight = (int)e.MarginBounds.Height;

            PaperSize paperSize = new PaperSize("A5Rotated", 830, 600);
            e.PageSettings.PaperSize = paperSize;

            SetInvoiceData(e.Graphics);
        }

    }
}
